home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / Toolkit.java < prev    next >
Text File  |  1998-09-22  |  29KB  |  803 lines

  1. /*
  2.  * @(#)Toolkit.java    1.73 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt;
  16.  
  17. import java.util.Properties;
  18. import java.awt.peer.*;
  19. import java.awt.image.ImageObserver;
  20. import java.awt.image.ImageProducer;
  21. import java.awt.image.ColorModel;
  22. import java.awt.datatransfer.Clipboard;
  23. import java.net.URL;
  24. import java.io.BufferedInputStream;
  25. import java.io.File;
  26. import java.io.FileInputStream;
  27.  
  28. /**
  29.  * This class is the abstract superclass of all actual
  30.  * implementations of the Abstract Window Toolkit. Subclasses of 
  31.  * <code>Toolkit</code> are used to bind the various components 
  32.  * to particular native toolkit implementations.
  33.  * <p>
  34.  * Most applications should not call any of the methods in this
  35.  * class directly. The methods defined by <code>Toolkit</code> are 
  36.  * the "glue" that joins the platform-independent classes in the 
  37.  * <code>java.awt</code> package with their counterparts in 
  38.  * <code>java.awt.peer</code>. Some methods defined by 
  39.  * <code>Toolkit</code> query the native operating system directly.
  40.  *
  41.  * @version     1.73, 07/01/98
  42.  * @author    Sami Shaio
  43.  * @author    Arthur van Hoff
  44.  * @since       JDK1.0
  45.  */
  46. public abstract class  Toolkit {
  47.  
  48.     /**
  49.      * Creates this toolkit's implementation of <code>Button</code> using 
  50.      * the specified peer interface.
  51.      * @param     target the button to be implemented.
  52.      * @return    this toolkit's implementation of <code>Button</code>.
  53.      * @see       java.awt.Button
  54.      * @see       java.awt.peer.ButtonPeer
  55.      * @since     JDK1.0
  56.      */
  57.     protected abstract ButtonPeer     createButton(Button target);
  58.  
  59.     /**
  60.      * Creates this toolkit's implementation of <code>TextField</code> using 
  61.      * the specified peer interface.
  62.      * @param     target the text field to be implemented.
  63.      * @return    this toolkit's implementation of <code>TextField</code>.
  64.      * @see       java.awt.TextField
  65.      * @see       java.awt.peer.TextFieldPeer
  66.      * @since     JDK1.0
  67.      */
  68.     protected abstract TextFieldPeer     createTextField(TextField target);
  69.  
  70.     /**
  71.      * Creates this toolkit's implementation of <code>Label</code> using 
  72.      * the specified peer interface.
  73.      * @param     target the label to be implemented.
  74.      * @return    this toolkit's implementation of <code>Label</code>.
  75.      * @see       java.awt.Label
  76.      * @see       java.awt.peer.LabelPeer
  77.      * @since     JDK1.0
  78.      */
  79.     protected abstract LabelPeer     createLabel(Label target);
  80.  
  81.     /**
  82.      * Creates this toolkit's implementation of <code>List</code> using 
  83.      * the specified peer interface.
  84.      * @param     target the list to be implemented.
  85.      * @return    this toolkit's implementation of <code>List</code>.
  86.      * @see       java.awt.List
  87.      * @see       java.awt.peer.ListPeer
  88.      * @since     JDK1.0
  89.      */
  90.     protected abstract ListPeer     createList(List target);
  91.  
  92.     /**
  93.      * Creates this toolkit's implementation of <code>Checkbox</code> using 
  94.      * the specified peer interface.
  95.      * @param     target the check box to be implemented.
  96.      * @return    this toolkit's implementation of <code>Checkbox</code>.
  97.      * @see       java.awt.Checkbox
  98.      * @see       java.awt.peer.CheckboxPeer
  99.      * @since     JDK1.0
  100.      */
  101.     protected abstract CheckboxPeer     createCheckbox(Checkbox target);
  102.  
  103.     /**
  104.      * Creates this toolkit's implementation of <code>Scrollbar</code> using 
  105.      * the specified peer interface.
  106.      * @param     target the scroll bar to be implemented.
  107.      * @return    this toolkit's implementation of <code>Scrollbar</code>.
  108.      * @see       java.awt.Scrollbar
  109.      * @see       java.awt.peer.ScrollbarPeer
  110.      * @since     JDK1.0
  111.      */
  112.     protected abstract ScrollbarPeer     createScrollbar(Scrollbar target);
  113.  
  114.     /**
  115.      * Creates this toolkit's implementation of <code>ScrollPane</code> using 
  116.      * the specified peer interface.
  117.      * @param     target the scroll pane to be implemented.
  118.      * @return    this toolkit's implementation of <code>ScrollPane</code>.
  119.      * @see       java.awt.ScrollPane
  120.      * @see       java.awt.peer.ScrollPanePeer
  121.      * @since     JDK1.1
  122.      */
  123.     protected abstract ScrollPanePeer     createScrollPane(ScrollPane target);
  124.  
  125.     /**
  126.      * Creates this toolkit's implementation of <code>TextArea</code> using 
  127.      * the specified peer interface.
  128.      * @param     target the text area to be implemented.
  129.      * @return    this toolkit's implementation of <code>TextArea</code>.
  130.      * @see       java.awt.TextArea
  131.      * @see       java.awt.peer.TextAreaPeer
  132.      * @since     JDK1.0
  133.      */
  134.     protected abstract TextAreaPeer      createTextArea(TextArea target);
  135.  
  136.     /**
  137.      * Creates this toolkit's implementation of <code>Choice</code> using 
  138.      * the specified peer interface.
  139.      * @param     target the choice to be implemented.
  140.      * @return    this toolkit's implementation of <code>Choice</code>.
  141.      * @see       java.awt.Choice
  142.      * @see       java.awt.peer.ChoicePeer
  143.      * @since     JDK1.0
  144.      */
  145.     protected abstract ChoicePeer    createChoice(Choice target);
  146.  
  147.     /**
  148.      * Creates this toolkit's implementation of <code>Frame</code> using 
  149.      * the specified peer interface.
  150.      * @param     target the frame to be implemented.
  151.      * @return    this toolkit's implementation of <code>Frame</code>.
  152.      * @see       java.awt.Frame
  153.      * @see       java.awt.peer.FramePeer
  154.      * @since     JDK1.0
  155.      */
  156.     protected abstract FramePeer      createFrame(Frame target);
  157.  
  158.     /**
  159.      * Creates this toolkit's implementation of <code>Canvas</code> using 
  160.      * the specified peer interface.
  161.      * @param     target the canvas to be implemented.
  162.      * @return    this toolkit's implementation of <code>Canvas</code>.
  163.      * @see       java.awt.Canvas
  164.      * @see       java.awt.peer.CanvasPeer
  165.      * @since     JDK1.0
  166.      */
  167.     protected abstract CanvasPeer     createCanvas(Canvas target);
  168.  
  169.     /**
  170.      * Creates this toolkit's implementation of <code>Panel</code> using 
  171.      * the specified peer interface.
  172.      * @param     target the panel to be implemented.
  173.      * @return    this toolkit's implementation of <code>Panel</code>.
  174.      * @see       java.awt.Panel
  175.      * @see       java.awt.peer.PanelPeer
  176.      * @since     JDK1.0
  177.      */
  178.     protected abstract PanelPeer      createPanel(Panel target);
  179.  
  180.     /**
  181.      * Creates this toolkit's implementation of <code>Window</code> using 
  182.      * the specified peer interface.
  183.      * @param     target the window to be implemented.
  184.      * @return    this toolkit's implementation of <code>Window</code>.
  185.      * @see       java.awt.Window
  186.      * @see       java.awt.peer.WindowPeer
  187.      * @since     JDK1.0
  188.      */
  189.     protected abstract WindowPeer      createWindow(Window target);
  190.  
  191.     /**
  192.      * Creates this toolkit's implementation of <code>Dialog</code> using 
  193.      * the specified peer interface.
  194.      * @param     target the dialog to be implemented.
  195.      * @return    this toolkit's implementation of <code>Dialog</code>.
  196.      * @see       java.awt.Dialog
  197.      * @see       java.awt.peer.DialogPeer
  198.      * @since     JDK1.0
  199.      */
  200.     protected abstract DialogPeer      createDialog(Dialog target);
  201.  
  202.     /**
  203.      * Creates this toolkit's implementation of <code>MenuBar</code> using 
  204.      * the specified peer interface.
  205.      * @param     target the menu bar to be implemented.
  206.      * @return    this toolkit's implementation of <code>MenuBar</code>.
  207.      * @see       java.awt.MenuBar
  208.      * @see       java.awt.peer.MenuBarPeer
  209.      * @since     JDK1.0
  210.      */
  211.     protected abstract MenuBarPeer      createMenuBar(MenuBar target);
  212.  
  213.     /**
  214.      * Creates this toolkit's implementation of <code>Menu</code> using 
  215.      * the specified peer interface.
  216.      * @param     target the menu to be implemented.
  217.      * @return    this toolkit's implementation of <code>Menu</code>.
  218.      * @see       java.awt.Menu
  219.      * @see       java.awt.peer.MenuPeer
  220.      * @since     JDK1.0
  221.      */
  222.     protected abstract MenuPeer      createMenu(Menu target);
  223.  
  224.     /**
  225.      * Creates this toolkit's implementation of <code>PopupMenu</code> using 
  226.      * the specified peer interface.
  227.      * @param     target the popup menu to be implemented.
  228.      * @return    this toolkit's implementation of <code>PopupMenu</code>.
  229.      * @see       java.awt.PopupMenu
  230.      * @see       java.awt.peer.PopupMenuPeer
  231.      * @since     JDK1.1
  232.      */
  233.     protected abstract PopupMenuPeer    createPopupMenu(PopupMenu target);
  234.  
  235.     /**
  236.      * Creates this toolkit's implementation of <code>MenuItem</code> using 
  237.      * the specified peer interface.
  238.      * @param     target the menu item to be implemented.
  239.      * @return    this toolkit's implementation of <code>MenuItem</code>.
  240.      * @see       java.awt.MenuItem
  241.      * @see       java.awt.peer.MenuItemPeer
  242.      * @since     JDK1.0
  243.      */
  244.     protected abstract MenuItemPeer      createMenuItem(MenuItem target);
  245.  
  246.     /**
  247.      * Creates this toolkit's implementation of <code>FileDialog</code> using 
  248.      * the specified peer interface.
  249.      * @param     target the file dialog to be implemented.
  250.      * @return    this toolkit's implementation of <code>FileDialog</code>.
  251.      * @see       java.awt.FileDialog
  252.      * @see       java.awt.peer.FileDialogPeer
  253.      * @since     JDK1.0
  254.      */
  255.     protected abstract FileDialogPeer    createFileDialog(FileDialog target);
  256.  
  257.     /**
  258.      * Creates this toolkit's implementation of <code>CheckboxMenuItem</code> using 
  259.      * the specified peer interface.
  260.      * @param     target the checkbox menu item to be implemented.
  261.      * @return    this toolkit's implementation of <code>CheckboxMenuItem</code>.
  262.      * @see       java.awt.CheckboxMenuItem
  263.      * @see       java.awt.peer.CheckboxMenuItemPeer
  264.      * @since     JDK1.0
  265.      */
  266.     protected abstract CheckboxMenuItemPeer    createCheckboxMenuItem(CheckboxMenuItem target);
  267.  
  268.     /**
  269.      * Creates a peer for a component or container.  This peer is windowless
  270.      * and allows the Component and Container classes to be extended directly
  271.      * to create windowless components that are defined entirely in java.
  272.      *
  273.      * @param target The Component to be created.
  274.      */
  275.     protected java.awt.peer.LightweightPeer createComponent(Component target) {
  276.     return new java.awt.LightweightPeer(target);
  277.     }
  278.  
  279.     /**
  280.      * Creates this toolkit's implementation of <code>Font</code> using 
  281.      * the specified peer interface.
  282.      * @param     target the font to be implemented.
  283.      * @return    this toolkit's implementation of <code>Font</code>.
  284.      * @see       java.awt.Font
  285.      * @see       java.awt.peer.FontPeer
  286.      * @since     JDK1.0
  287.      */
  288.     protected abstract FontPeer getFontPeer(String name, int style);
  289.  
  290.     /**
  291.      * Fills in the integer array that is supplied as an argument 
  292.      * with the current system color values.
  293.      * <p>
  294.      * This method is called by the method <code>updateSystemColors</code>
  295.      * in the <code>SystemColor</code> class.
  296.      * @param     an integer array.
  297.      * @see       java.awt.SystemColor#updateSystemColors
  298.      * @since     JDK1.1
  299.      */
  300.     protected void loadSystemColors(int[] systemColors) {
  301.     }
  302.  
  303.     /**
  304.      * Gets the size of the screen.
  305.      * @return    the size of this toolkit's screen, in pixels.
  306.      * @since     JDK1.0
  307.      */
  308.     public abstract Dimension getScreenSize();
  309.  
  310.     /**
  311.      * Returns the screen resolution in dots-per-inch.
  312.      * @return    this toolkit's screen resolution, in dots-per-inch.
  313.      * @since     JDK1.0
  314.      */
  315.     public abstract int getScreenResolution();
  316.  
  317.     /**
  318.      * Determines the color model of this toolkit's screen. 
  319.      * <p>
  320.      * <code>ColorModel</code> is an abstract class that 
  321.      * encapsulates the ability to translate between the 
  322.      * pixel values of an image and its red, green, blue, 
  323.      * and alpha components. 
  324.      * <p>
  325.      * This toolkit method is called by the 
  326.      * <code>getColorModel</code> method 
  327.      * of the <code>Component</code> class. 
  328.      * @return    the color model of this toolkit's screen.
  329.      * @see       java.awt.image.ColorModel
  330.      * @see       java.awt.Component#getColorModel
  331.      * @since     JDK1.0
  332.      */
  333.     public abstract ColorModel getColorModel();
  334.  
  335.     /**
  336.      * Returns the names of the available fonts in this toolkit.<p>
  337.      * For 1.1, the following font names are deprecated (the replacement
  338.      * name follows):
  339.      * <ul>
  340.      * <li>TimesRoman (use Serif)
  341.      * <li>Helvetica (use SansSerif)
  342.      * <li>Courier (use Monospaced)
  343.      * </ul><p>
  344.      * The ZapfDingbats font is also deprecated in 1.1, but only as a
  345.      * separate fontname.  Unicode defines the ZapfDingbat characters
  346.      * starting at \u2700, and as of 1.1 Java supports those characters.
  347.      * @return    the names of the available fonts in this toolkit.
  348.      * @since     JDK1.0
  349.      */
  350.     public abstract String[] getFontList();
  351.  
  352.     /**
  353.      * Gets the screen metrics of the font.
  354.      * @param     font   a font.
  355.      * @return    the screen metrics of the specified font in this toolkit.
  356.      * @since     JDK1.0
  357.      */
  358.     public abstract FontMetrics getFontMetrics(Font font);
  359.  
  360.     /**
  361.      * Synchronizes this toolkit's graphics state. Some window systems 
  362.      * may do buffering of graphics events. 
  363.      * <p>
  364.      * This method ensures that the display is up-to-date. It is useful
  365.      * for animation.
  366.      * @since     JDK1.0
  367.      */
  368.     public abstract void sync();
  369.  
  370.     /**
  371.      * The default toolkit.
  372.      */
  373.     private static Toolkit toolkit;
  374.  
  375.     /**
  376.      * Gets the default toolkit. 
  377.      * <p>
  378.      * If there is a system property named <code>"awt.toolkit"</code>, 
  379.      * that property is treated as the name of a class that is a subclass 
  380.      * of <code>Toolkit</code>. 
  381.      * <p>
  382.      * If the system property does not exist, then the default toolkit 
  383.      * used is the class named <code>"sun.awt.motif.MToolkit"</code>, 
  384.      * which is a motif implementation of the Abstract Window Toolkit. 
  385.      * @return    the default toolkit.
  386.      * @exception  AWTError  if a toolkit could not be found, or 
  387.      *                 if one could not be accessed or instantiated.
  388.      * @since     JDK1.0
  389.      */
  390.     public static synchronized Toolkit getDefaultToolkit() {
  391.     if (toolkit == null) {
  392.         String nm = System.getProperty("awt.toolkit", "sun.awt.motif.MToolkit");
  393.         try {
  394.         toolkit = (Toolkit)Class.forName(nm).newInstance();
  395.         } catch (ClassNotFoundException e) {
  396.         throw new AWTError("Toolkit not found: " + nm);
  397.         } catch (InstantiationException e) {
  398.         throw new AWTError("Could not instantiate Toolkit: " + nm);
  399.         } catch (IllegalAccessException e) {
  400.         throw new AWTError("Could not access Toolkit: " + nm);
  401.         }
  402.     }
  403.     return toolkit;
  404.     }
  405.  
  406.     /**
  407.      * Returns an image which gets pixel data from the specified file.
  408.      * @param     filename   the name of a file containing pixel data 
  409.      *                         in a recognized file format.
  410.      * @return    an image which gets its pixel data from 
  411.      *                         the specified file.
  412.      * @since     JDK1.0
  413.      */
  414.     public abstract Image getImage(String filename);
  415.  
  416.     /**
  417.      * Returns an image which gets pixel data from the specified URL.
  418.      * @param     url   the URL to use in fetching the pixel data.
  419.      * @return    an image which gets its pixel data from 
  420.      *                         the specified URL.
  421.      * @since     JDK1.0
  422.      */
  423.     public abstract Image getImage(URL url);
  424.  
  425.     /**
  426.      * Prepares an image for rendering. 
  427.      * <p>
  428.      * If the values of the width and height arguments are both 
  429.      * <code>-1</code>, this method prepares the image for rendering 
  430.      * on the default screen; otherwise, this method prepares an image 
  431.      * for rendering on the default screen at the specified width and height. 
  432.      * <p>
  433.      * The image data is downloaded asynchronously in another thread, 
  434.      * and an appropriately scaled screen representation of the image is 
  435.      * generated. 
  436.      * <p>
  437.      * This method is called by components <code>prepareImage</code> 
  438.      * methods. 
  439.      * <p>
  440.      * Information on the flags returned by this method can be found 
  441.      * with the definition of the <code>ImageObserver</code> interface. 
  442.  
  443.      * @param     image      the image for which to prepare a  
  444.      *                           screen representation.
  445.      * @param     width      the width of the desired screen 
  446.      *                           representation, or <code>-1</code>.
  447.      * @param     height     the height of the desired screen 
  448.      *                           representation, or <code>-1</code>.
  449.      * @param     observer   the <code>ImageObserver</code> 
  450.      *                           object to be notified as the 
  451.      *                           image is being prepared.
  452.      * @return    <code>true</code> if the image has already been 
  453.      *                 fully prepared; <code>false</code> otherwise.
  454.      * @see       java.awt.Component#prepareImage(java.awt.Image, 
  455.      *                 java.awt.image.ImageObserver)
  456.      * @see       java.awt.Component#prepareImage(java.awt.Image, 
  457.      *                 int, int, java.awt.image.ImageObserver)
  458.      * @see       java.awt.image.ImageObserver
  459.      * @since     JDK1.0
  460.      */
  461.     public abstract boolean prepareImage(Image image, int width, int height,
  462.                      ImageObserver observer);
  463.  
  464.     /**
  465.      * Indicates the construction status of a specified image that is
  466.      * being prepared for display.
  467.      * <p>
  468.      * If the values of the width and height arguments are both 
  469.      * <code>-1</code>, this method returns the construction status of 
  470.      * a screen representation of the specified image in this toolkit. 
  471.      * Otherwise, this method returns the construction status of a
  472.      * scaled representation of the image at the specified width 
  473.      * and height.
  474.      * <p>
  475.      * This method does not cause the image to begin loading. 
  476.      * An application must call <code>prepareImage</code> to force 
  477.      * the loading of an image.
  478.      * <p>
  479.      * This method is called by the component's <code>checkImage</code>
  480.      * methods.
  481.      * <p>
  482.      * Information on the flags returned by this method can be found
  483.      * with the definition of the <code>ImageObserver</code> interface.
  484.      * @param     image   the image whose status is being checked.
  485.      * @param     width   the width of the scaled version whose status is
  486.      *                 being checked, or <code>-1</code>.
  487.      * @param     height  the height of the scaled version whose status
  488.      *                 is being checked, or <code>-1</code>.
  489.      * @param     observer   the <code>ImageObserver</code> object to be
  490.      *                 notified as the image is being prepared.
  491.      * @return    the bitwise inclusive <strong>OR</strong> of the
  492.      *                 <code>ImageObserver</code> flags for the 
  493.      *                 image data that is currently available.
  494.      * @see       java.awt.Toolkit#prepareImage(java.awt.Image, 
  495.      *                 int, int, java.awt.image.ImageObserver)
  496.      * @see       java.awt.Component#checkImage(java.awt.Image, 
  497.      *                 java.awt.image.ImageObserver)
  498.      * @see       java.awt.Component#checkImage(java.awt.Image, 
  499.      *                 int, int, java.awt.image.ImageObserver)
  500.      * @see       java.awt.image.ImageObserver
  501.      * @since     JDK1.0
  502.      */
  503.     public abstract int checkImage(Image image, int width, int height,
  504.                    ImageObserver observer);
  505.  
  506.     /**
  507.      * Creates an image with the specified image producer.
  508.      * @param     producer the image producer to be used.
  509.      * @return    an image with the specified image producer.
  510.      * @see       java.awt.Image
  511.      * @see       java.awt.image.ImageProducer
  512.      * @see       java.awt.Component#createImage(java.awt.image.ImageProducer)
  513.      * @since     JDK1.0
  514.      */
  515.     public abstract Image createImage(ImageProducer producer);
  516.  
  517.     /**
  518.      * Creates an image which decodes the image stored in the specified
  519.      * byte array.
  520.      * <p>
  521.      * The data must be in some image format, such as GIF or JPEG, 
  522.      * that is supported by this toolkit.
  523.      * @param     imagedata   an array of bytes, representing 
  524.      *                         image data in a supported image format.
  525.      * @return    an image.
  526.      * @since     JDK1.1
  527.      */
  528.     public Image createImage(byte[] imagedata) {
  529.     return createImage(imagedata, 0, imagedata.length);
  530.     }
  531.  
  532.     /**
  533.      * Creates an image which decodes the image stored in the specified
  534.      * byte array, and at the specified offset and length.
  535.      * The data must be in some image format, such as GIF or JPEG, 
  536.      * that is supported by this toolkit. 
  537.      * @param     imagedata   an array of bytes, representing 
  538.      *                         image data in a supported image format.
  539.      * @param     imageoffset  the offset of the beginning 
  540.      *                         of the data in the array.
  541.      * @param     imagelength  the length of the data in the array.
  542.      * @return    an image.
  543.      * @since     JDK1.1
  544.      */
  545.     public abstract Image createImage(byte[] imagedata,
  546.                       int imageoffset,
  547.                       int imagelength);
  548.  
  549.     /**
  550.      * Gets a <code>PrintJob</code> object which is the result 
  551.      * of initiating a print operation on the toolkit's platform. 
  552.      * @return    a <code>PrintJob</code> object, or 
  553.      *                  <code>null</code> if the user 
  554.      *                  cancelled the print job.
  555.      * @see       java.awt.PrintJob
  556.      * @since     JDK1.1
  557.      */
  558.     public abstract PrintJob getPrintJob(Frame frame, String jobtitle, Properties props);
  559.  
  560.     /**
  561.      * Emits an audio beep.
  562.      * @since     JDK1.1
  563.      */
  564.     public abstract void beep();
  565.  
  566.     /**
  567.      * Gets an instance of the system clipboard which interfaces 
  568.      * with clipboard facilities provided by the native platform. 
  569.      * <p>
  570.      * This clipboard enables data transfer between Java programs 
  571.      * and native applications which use native clipboard facilities.
  572.      * @return    an instance of the system clipboard.
  573.      * @see       java.awt.datatransfer.Clipboard
  574.      * @since     JDK1.1
  575.      */
  576.     public abstract Clipboard getSystemClipboard();
  577.  
  578.     /**
  579.      * Determines which modifier key is the appropriate accelerator
  580.      * key for menu shortcuts.
  581.      * <p>
  582.      * Menu shortcuts, which are embodied in the 
  583.      * <code>MenuShortcut</code> class, are handled by the 
  584.      * <code>MenuBar</code> class.
  585.      * <p>
  586.      * By default, this method returns <code>Event.CTRL_MASK</code>.
  587.      * Toolkit implementations should override this method if the
  588.      * <b>Control</b> key isn't the correct key for accelerators.
  589.      * @return    the modifier mask on the <code>Event</code> class 
  590.      *                 that is used for menu shortcuts on this toolkit. 
  591.      * @see       java.awt.MenuBar
  592.      * @see       java.awt.MenuShortcut
  593.      * @since     JDK1.1
  594.      */
  595.     public int getMenuShortcutKeyMask() {
  596.         return Event.CTRL_MASK;
  597.     }
  598.  
  599.     /**
  600.      * Give native peers the ability to query the native container 
  601.      * given a native component (eg the direct parent may be lightweight).
  602.      */
  603.     protected static Container getNativeContainer(Component c) {
  604.     return c.getNativeContainer();
  605.     }
  606.  
  607.     /* Support for I18N: any visible strings should be stored in 
  608.      * lib/awt.properties.  The Properties list is stored here, so
  609.      * that only one copy is maintained.
  610.      */
  611.     private static Properties properties;
  612.     static {
  613.         String sep = File.separator;
  614.         File propsFile = new File(
  615.             System.getProperty("java.home") + sep + "lib" +
  616.             sep + "awt.properties");
  617.         properties = new Properties();
  618.     try {
  619.         FileInputStream in =
  620.         new FileInputStream(propsFile);
  621.         properties.load(new BufferedInputStream(in));
  622.         in.close();
  623.     } catch (Exception e) {
  624.             // No properties, defaults will be used.
  625.     }
  626.     }
  627.  
  628.     /**
  629.      * Gets a property with the specified key and default. 
  630.      * This method returns defaultValue if the property is not found.
  631.      */
  632.     public static String getProperty(String key, String defaultValue) {
  633.     String val = properties.getProperty(key);
  634.     return (val == null) ? defaultValue : val;
  635.     }
  636.  
  637.     /**
  638.      * Get the application's or applet's EventQueue instance.  
  639.      * Depending on the Toolkit implementation, different EventQueues 
  640.      * may be returned for different applets.  Applets should 
  641.      * therefore not assume that the EventQueue instance returned
  642.      * by this method will be shared by other applets or the system.
  643.      */
  644.     public final EventQueue getSystemEventQueue() {
  645.         SecurityManager security = System.getSecurityManager();
  646.         if (security != null) {
  647.       security.checkAwtEventQueueAccess();
  648.         }
  649.         return getSystemEventQueueImpl();
  650.     }
  651.  
  652.     /*
  653.      * Get the application's or applet's EventQueue instance, without
  654.      * checking access.  For security reasons, this can only be called 
  655.      * from a Toolkit subclass.  Implementations wishing to modify
  656.      * the default EventQueue support should subclass this method.
  657.      */
  658.     protected abstract EventQueue getSystemEventQueueImpl();
  659.  
  660.     /* Accessor method for use by AWT package routines. */
  661.     static EventQueue getEventQueue() {
  662.         return toolkit.getSystemEventQueueImpl();
  663.     }
  664. }
  665.  
  666.  
  667.  
  668. /**
  669.  * Implements the LightweightPeer interface for use in lightweight components
  670.  * that have no native window associated with them.  This gets created by
  671.  * default in Component so that Component and Container can be directly
  672.  * extended to create useful components written entirely in java.  These 
  673.  * components must be hosted somewhere higher up in the component tree by a 
  674.  * native container (such as a Frame).
  675.  *
  676.  * This implementation provides no useful semantics and serves only as a
  677.  * marker.  One could provide alternative implementations in java that do
  678.  * something useful for some of the other peer interfaces to minimize the
  679.  * native code.
  680.  *
  681.  * @author Timothy Prinzing
  682.  */
  683. class LightweightPeer implements java.awt.peer.LightweightPeer {
  684.  
  685.     public LightweightPeer(Component target) {
  686.     }
  687.  
  688.     public boolean isFocusTraversable() {
  689.     return false;
  690.     }
  691.  
  692.     public void setVisible(boolean b) {
  693.     }
  694.  
  695.     public void show() {
  696.     }
  697.  
  698.     public void hide() {
  699.     }
  700.  
  701.     public void setEnabled(boolean b) {
  702.     }
  703.  
  704.     public void enable() {
  705.     }
  706.  
  707.     public void disable() {
  708.     }
  709.  
  710.     public void paint(Graphics g) {
  711.     }
  712.  
  713.     public void repaint(long tm, int x, int y, int width, int height) {
  714.     }
  715.  
  716.     public void print(Graphics g) {
  717.     }
  718.  
  719.     public void setBounds(int x, int y, int width, int height) {
  720.     }
  721.  
  722.     public void reshape(int x, int y, int width, int height) {
  723.     }
  724.  
  725.     public boolean handleEvent(Event e) {
  726.     return false;
  727.     }
  728.  
  729.     public void handleEvent(java.awt.AWTEvent arg0) {
  730.     }
  731.  
  732.     public Dimension getPreferredSize() {
  733.     return new Dimension(1,1);
  734.     }
  735.  
  736.     public Dimension getMinimumSize() {
  737.     return new Dimension(1,1);
  738.     }
  739.  
  740.     public java.awt.Toolkit getToolkit() {
  741.     return null;
  742.     }
  743.  
  744.     public ColorModel getColorModel() {
  745.     return null;
  746.     }
  747.  
  748.     public Graphics getGraphics() {
  749.     return null;
  750.     }
  751.  
  752.     public FontMetrics    getFontMetrics(Font font) {
  753.     return null;
  754.     }
  755.  
  756.     public void dispose() {
  757.     // no native code
  758.     }
  759.  
  760.     public void setForeground(Color c) {
  761.     }
  762.  
  763.     public void setBackground(Color c) {
  764.     }
  765.  
  766.     public void setFont(Font f) {
  767.     }
  768.  
  769.     public void setCursor(Cursor cursor) {
  770.     }
  771.  
  772.     public void requestFocus() {
  773.     }
  774.  
  775.     public Image createImage(ImageProducer producer) {
  776.     return null;
  777.     }
  778.  
  779.     public Image createImage(int width, int height) {
  780.     return null;
  781.     }
  782.  
  783.     public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
  784.     return false;
  785.     }
  786.  
  787.     public int    checkImage(Image img, int w, int h, ImageObserver o) {
  788.     return 0;
  789.     }
  790.  
  791.     public Dimension preferredSize() {
  792.     return getPreferredSize();
  793.     }
  794.  
  795.     public Dimension minimumSize() {
  796.     return getMinimumSize();
  797.     }
  798.  
  799.     public Point getLocationOnScreen() {
  800.     return null;
  801.     }
  802. }
  803.